package com.xyh.jdkDemo;


import java.io.IOException;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xyh.jdkDemo
 * @类名称：classLoaderDemo
 * @创建人：YIHANG.XU
 * @创建时间：2020/9/149:27 下午
 * @修改人：YIHANG.XU
 * @修改时间：2020/9/149:27 下午
 * @修改备注：
 * @Copyright
 */
public class ClassLoaderDemo extends ClassLoader {
    private static final String BASE_DIR = "data/c87/";
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        String fileName = name.replaceAll("\\.", "/");
        fileName = BASE_DIR + fileName + ".class";
        try {
            byte[] bytes = BinaryFileUtils.readFileToByteArray(fileName);
            return defineClass(name, bytes, 0, bytes.length);
        } catch (IOException ex) {
            throw new ClassNotFoundException("failed to load class " + name, ex);
        }
    }
}
